Skip to content

feat: add support for reading from Optionals with parameter customizers - #3370

Merged
bnasslahsen merged 1 commit into
springdoc:mainfrom
Mattias-Sehlstedt:customizers-read-from-optional
Oct 23, 2026
Merged

bnasslahsen merged 1 commit into
springdoc:mainfrom
Mattias-Sehlstedt:customizers-read-from-optional

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Similar to #3331 but for the customizers that springdoc offer to interpret annotations to schema decoration.

Note that this only affects ParameterCustomizers, and not PropertyCustomizers. This is because the ModelResolver currently does not propagate any annotation within an Optional. I will investigate how to best achieve so that these annotation can also be propagated and then discovered in the PropertyCustomizer.

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the customizers-read-from-optional branch 2 times, most recently from ddf4a91 to 7c6f82c Compare September 21, 2026 18:15
@Mattias-Sehlstedt Mattias-Sehlstedt changed the title feat: add support for reading from Optional parameters with customizers feat: add support for reading from Optionals with customizers Sep 21, 2026
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the customizers-read-from-optional branch from 7c6f82c to b17f88b Compare September 21, 2026 19:55
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the customizers-read-from-optional branch from b17f88b to 7fae659 Compare October 2, 2026 18:28
@Mattias-Sehlstedt Mattias-Sehlstedt changed the title feat: add support for reading from Optionals with customizers feat: add support for reading from Optionals with parameter customizers Oct 2, 2026
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the customizers-read-from-optional branch from 7fae659 to 96fe42d Compare October 2, 2026 19:20
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the customizers-read-from-optional branch from 96fe42d to e95228e Compare October 23, 2026 16:44
bnasslahsen added a commit that referenced this pull request Oct 23, 2026
The type-use annotations of a parameter are passed as parameter
annotations, which also drive the required detection: a value declared
as Optional<@NotNull String> made the parameter required. Skip the
annotations marking a value as required on the type wrapped in an
Optional, as they constrain the value when present, and skip type-use
annotations already declared on the parameter.

Restore the formatting of the code left unchanged, add app277 to cover
the optional parameter, and reword the changelog entry.

See gh-3370

Signed-off-by: Badr NASS LAHSEN <badr.nasslahsen@gmail.com>
@bnasslahsen
bnasslahsen merged commit 70da69a into springdoc:main Oct 23, 2026
1 check passed
bnasslahsen pushed a commit that referenced this pull request Oct 23, 2026
ParameterCustomizer implementations can now read the type-use
annotations of a parameter, including the ones declared on the value
wrapped in an Optional. The annotations marking a value as required are
not taken from inside an Optional, so that Optional<@NotNull String>
stays optional.

Backport of gh-3370

Signed-off-by: Badr NASS LAHSEN <badr.nasslahsen@gmail.com>
@bnasslahsen

Copy link
Copy Markdown
Collaborator

Thanks @Mattias-Sehlstedt! Merged with a follow-up, keeping your tests: the type-use annotations are passed as parameter annotations, which also drive the required detection, so Optional<@NotNull String> became a required parameter. The annotations marking a value as required are no longer taken from inside an Optional (#3331 already applies them to the schema), and app277 covers that case. Backported to spring-boot-3 (587af24).

@Mattias-Sehlstedt
Mattias-Sehlstedt deleted the customizers-read-from-optional branch October 24, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants